#include "CableDeliverySystemDescriptor.h"

CCableDeliverySystemDescriptor::CCableDeliverySystemDescriptor(void):IDescriptorData(DESCRIPTOR_TAG_CABLE_DELIVERY_SYSTEM)
, m_fFrequency(0)
, m_fSymbolRate(0) 
, m_byModulation(0)
, m_byFECOuter(0) 
, m_byFECInner(0)  
{
}

CCableDeliverySystemDescriptor::~CCableDeliverySystemDescriptor(void)
{
}


void CCableDeliverySystemDescriptor::GetData(BYTE* buff  , int &len)
{   
	std::string			csfFrequency;
	std::string			csfSymbolRate;
	std::string			csbyModulation;
	std::string			csbyFECOuter;
	std::string			csbyFECInner; 

	csfFrequency = ConvertToString(((int)m_fFrequency)*10000);
	csfSymbolRate = ConvertToString(m_fSymbolRate*10);
	csbyModulation = ConvertToStringHex(m_byModulation);
	csbyFECOuter = ConvertToStringHex(m_byFECOuter);
	csbyFECInner = ConvertToString(m_byFECInner);

	std::string descriptor = "440B";//cable tag = 0x44; length = 0x0B;
	std::string strTemp = "";

	strTemp = csfFrequency;
	for (int i=0; i<(8-strTemp.length()); i++)
	{
		descriptor += "0";
	}
	descriptor += strTemp;

	descriptor += "FFF";
	strTemp = csbyFECOuter;
	descriptor += strTemp;

	strTemp = csbyModulation;
	for (int i=0; i<(2-strTemp.length()); i++)
	{
		descriptor += "0";
	}
	descriptor += strTemp;

	strTemp = csfSymbolRate;
	for (int i=0; i<(7-strTemp.length()); i++)
	{
		descriptor += "0";
	}
	descriptor += strTemp;

	strTemp = csbyFECInner;
	descriptor += strTemp;
	unsigned char cslen = 0;
	STR_HEX((char *)descriptor.c_str(),descriptor.length(),buff,(unsigned char*)&cslen) ;
 
	len = cslen;
}